# -*- coding: utf-8 -*-
class MemoryUse:
     def returnMemUse(self):
	Total = self.ReturnFromLine("MemTotal:")
	Free = self.ReturnFromLine("MemFree:")
	text = str(100*(float(Total) - float(Free))/float(Total))
	vT = 0
	while text[vT] != ".":
	    vT+=1
	memtext = text[0:vT+3] + " %"
	return memtext
    
     def returnSwapUse(self):
	Total = self.ReturnFromLine("SwapTotal:")
	Free = self.ReturnFromLine("SwapFree:")
	if float(Total) != 0 :
	    text = str(100*(float(Total) - float(Free))/float(Total))
	else:
	    memtext = "00.00"
	vT = 0
	while memtext[vT] != ".":
	    vT+=1
	memtext = memtext[0:vT+3] + " %"
	return memtext
    
     def returnTotalMem(self):
	myfile =  open ("/proc/meminfo", 'r')
	text = myfile.read()
	myfile.close()
	Total = self.ReturnFromLine("MemTotal:")
	Total.strip()
	Total = str(float(Total)/1000000) + " GB"
	return Total
      
     def ReturnFromLine(self, LineName):
	myfile =  open ("/proc/meminfo", 'r')
	text = myfile.read()
	myfile.close()
	vT = text.find(LineName)
	while text[vT] != " ":
	    vT+=1
	while text[vT] == " ":
	    vT+=1
	endT = vT
	while text[endT] != " ":
	    endT+=1
	besttext = text[vT:endT]
	besttext.strip()
	return besttext 
